package gazzera.experimental;

import java.util.concurrent.*;

public class ExecutorTest implements Callable<String>
{

	
	
	@Override
	public String call() throws Exception
	{
		for (int i = 0; i < 40000; i++)
		{
			System.out.println(Thread.interrupted() + " " +i);
		}
		
		//if(true) throw new NumberFormatException("ciao");
		return "Ok";
	}

	public static void main(String[] args)
	{
		ExecutorService s = Executors.newCachedThreadPool();
		
		Future<String> f = s.submit(new ExecutorTest());
		
		try
		{
			Thread.sleep(500);
			f.cancel(true);
			System.out.println("Result: "+f.get());
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		
		s.shutdown();
	}
}
